import { _decorator, Button, Component, director, find, Label, Node, Sprite, SpriteFrame, tween, Vec3 } from 'cc';
import { EntityManager } from '../Base/EntityManager';
import { EItemType } from './Item';
import { EEvent, EMaterialtype, EState } from '../Config/Enum';
import { IdleStateMachine } from './IdleStateMachine';
import ObjectPoolManager from '../Core/ObjectPoolManager';
import { BattleManager } from '../BattleManager';
import { GoldPerEnemy } from '../Config/Config';
import { Core } from '../Core/Core';

const { ccclass, property } = _decorator;

// 铜钱动画
@ccclass('Coin')
export class Coin extends EntityManager {

    init(){
        this.fsm = this.node.getComponent(IdleStateMachine) || this.node.addComponent(IdleStateMachine);
        this.fsm.init("Coin", 0.2, 2)
        this.state = EState.Idle
        this.node.setScale(0.5,0.5,1)


    }

    protected onLoad(): void {
        
    }

    onEnable(){
        tween(this.node)

            .delay(0.5)
            .to(1, { position: new Vec3(-50,350,0) })
            .call(() => {

                BattleManager.Instance.gold += BattleManager.Instance.goldPerEnemy;
                Core.Instance.event.emit(EEvent.MoneyUpdateHeader, this);

                ObjectPoolManager.Instance.ret(this.node);
            })
            .start();
    }








}